#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 210, M = N * N;
int p[M];
int n, m;
int get(int x, int y)
{
    return x * n + y;
}
int find(int x)
{
    if (p[x] != x) p[x] = find(p[x]);
    return p[x];
}
int main()
{
    cin >> n >> m;
    for (int i = 0; i < n * n; i++) p[i] = i;
    int res = 0;
    for (int i = 1; i <= m; i++)
    {
        int x, y, a, b;
        char c;
        cin >> x >> y >> c;
        x--, y--;
        a = get(x, y);
        if (c == 'D') b = get(x + 1, y);
        else b = get(x, y + 1);
        int pa = find(a);
        int pb = find(b);
        if (pa == pb)
        {
            res = i;
            break;
        }
        p[pa] = pb;
    }
    if (!res) cout << "draw" << endl;
    else cout << res << endl;
    return 0;
}